package com.cc.controller;



import com.cc.pojo.EmpQueryParam;
import com.cc.pojo.PageResult;
import com.cc.pojo.Result;
import com.cc.pojo.Student;
import com.cc.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping
    public Result list(EmpQueryParam empQueryParam){
        log.info("查询所有员工");
        PageResult<Student> studentList = studentService.list(empQueryParam);
        return Result.success(studentList);
    }

    @DeleteMapping("/{ids}")
    public  Result delect(@PathVariable List<Integer> ids){
        log.info("批量删除学生: ids={}", ids);
        studentService.delect(ids);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Student student){
        log.info("添加员工: {}", student);
        studentService.add(student);
        return Result.success();
    }

    @GetMapping("/{id}")
    public  Result getById(@PathVariable Integer id){
        log.info("查询学生: {}", id);
        Student student=studentService.getID(id);
        return Result.success(student);
    }

    @PutMapping
    public Result update(@RequestBody Student student){
        log.info("修改员工: {}", student);
        studentService.update(student);
        return Result.success();
    }

    @PutMapping("/{violation}/{id}/{score}")
    public Result weiji(@PathVariable Integer id,@PathVariable Integer score){
        log.info ("学员违纪处理，学员ID：{}，扣分数值：{}", id, score);
       boolean isSuccess= studentService.weiji(id,score);
       if (isSuccess){
           return Result.success();
       }else {
           return Result.error("操作失败");
       }

    }
}
